package com.yanqu.road.entity.activity.unionwar.cross;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.yanqu.road.entity.DataObject;
import com.yanqu.road.utils.BigIntegerDeserializer;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;


public class CrossUnionWarDetail extends DataObject {
    private int activityId;      //活动编号
    private int stageNo;         //活动阶段
    private int roundNo;         //轮次
    private String unionUid;     //商会编号
    private String enemyUnionUid = "";    //对手商会
    private long modifyTime;         //变更时间
    private List<Long> matchSync = new ArrayList<>();               //对阵匹配结果同步状态(0:区服未接收；1：区服已接收) 改成已同步区服id
    private int no;                  //本轮次编号
    private int enemyNo;             //本轮次对手编号
    private int winMark;             //胜负标识，0：初始值；1：胜；2：负；3：轮空
    private List<Long> resultSync = new ArrayList<>();         //战斗结果同步状态（0：未同步；1：已同步，区服反馈）改成已同步区服id
    @JSONField(deserializeUsing = BigIntegerDeserializer.class)
    private BigInteger totalSilver = BigInteger.ZERO;        //总银两数量
    @JSONField(deserializeUsing = BigIntegerDeserializer.class)
    private BigInteger totalAbility = BigInteger.ZERO;       //总能力值
    private boolean isTopMatch;                              //精彩对阵
    private List<UnionWarPatronsData> patronsDataList = new ArrayList<>();       //出战门客集合
    private Map<Long, UnionWarUserData> userDataMap = new ConcurrentHashMap<>();
    private boolean addScore;       //是否已计分
    private int groupId;
    List<Long> readUserId = new ArrayList<>();

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if(this.activityId != activityId) {
            this.activityId = activityId;
            setUpdateOption();
        }
    }

    public int getStageNo() {
        return stageNo;
    }

    public void setStageNo(int stageNo) {
        if(this.stageNo != stageNo) {
            this.stageNo = stageNo;
            setUpdateOption();
        }
    }

    public int getRoundNo() {
        return roundNo;
    }

    public void setRoundNo(int roundNo) {
        if(this.roundNo != roundNo) {
            this.roundNo = roundNo;
            setUpdateOption();
        }
    }

    public String getUnionUid() {
        return unionUid;
    }

    public void setUnionUid(String unionUid) {
        if(!Objects.equals(this.unionUid, unionUid)) {
            this.unionUid = unionUid;
            setUpdateOption();
        }
    }

    public String getEnemyUnionUid() {
        return enemyUnionUid;
    }

    public void setEnemyUnionUid(String enemyUnionUid) {
        if (enemyUnionUid == null) {
            return;
        }
        if(!Objects.equals(this.enemyUnionUid, enemyUnionUid)) {
            this.enemyUnionUid = enemyUnionUid;
            setUpdateOption();
        }
    }

    public long getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(long modifyTime) {
        if(this.modifyTime != modifyTime) {
            this.modifyTime = modifyTime;
            setUpdateOption();
        }
    }

    public List<Long> getMatchSync() {
        return matchSync;
    }

    public void setMatchSync(List<Long> matchSync) {
        if(this.matchSync != matchSync) {
            this.matchSync = matchSync;
            setUpdateOption();
        }
    }

    public void addMatchSyncServerId(Long serverId) {
        this.matchSync.add(serverId);
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        if(this.no != no) {
            this.no = no;
            setUpdateOption();
        }
    }

    public int getEnemyNo() {
        return enemyNo;
    }

    public void setEnemyNo(int enemyNo) {
        if(this.enemyNo != enemyNo) {
            this.enemyNo = enemyNo;
            setUpdateOption();
        }
    }

    public int getWinMark() {
        return winMark;
    }

    public void setWinMark(int winMark) {
        if(this.winMark != winMark) {
            this.winMark = winMark;
            setUpdateOption();
        }
    }

    public List<Long> getResultSync() {
        return resultSync;
    }

    public void setResultSync(List<Long> resultSync) {
        if(this.resultSync != resultSync) {
            this.resultSync = resultSync;
            setUpdateOption();
        }
    }

    public void addResultSync(long serverId) {
        this.resultSync.add(serverId);
    }

    public BigInteger getTotalSilver() {
        return totalSilver;
    }

    public void setTotalSilver(BigInteger totalSilver) {
        if(!Objects.equals(this.totalSilver, totalSilver)) {
            this.totalSilver = totalSilver;
            setUpdateOption();
        }
    }

    public BigInteger getTotalAbility() {
        return totalAbility;
    }

    public void setTotalAbility(BigInteger totalAbility) {
        if(!Objects.equals(this.totalAbility, totalAbility)) {
            this.totalAbility = totalAbility;
            setUpdateOption();
        }
    }

    public boolean isTopMatch() {
        return isTopMatch;
    }

    public void setTopMatch(boolean topMatch) {
        if(this.isTopMatch != topMatch) {
            isTopMatch = topMatch;
            setUpdateOption();
        }
    }

    public List<UnionWarPatronsData> getPatronsDataList() {
        return patronsDataList;
    }

    public void setPatronsDataList(List<UnionWarPatronsData> patronsDataList) {
        this.patronsDataList = patronsDataList;
        setUpdateOption();
    }

    public String getPatronsDataListJsonStr() {
        return JSON.toJSONString(patronsDataList);
    }

    public Map<Long, UnionWarUserData> getUserDataMap() {
        return userDataMap;
    }

    public void setUserDataMap(Map<Long, UnionWarUserData> userDataMap) {
        this.userDataMap = userDataMap;
        setUpdateOption();
    }

    public void addUserDataMap(UnionWarUserData userData){
        this.userDataMap.put(userData.getUserId(), userData);
        setUpdateOption();
    }

    public String getUserDataMapJsonStr() {
        return JSON.toJSONString(userDataMap);
    }

    public boolean isAddScore() {
        return addScore;
    }

    public void setAddScore(boolean addScore) {
        if(this.addScore != addScore) {
            this.addScore = addScore;
            setUpdateOption();
        }
    }

    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        if(this.groupId != groupId){
            this.groupId = groupId;
            setUpdateOption();
        }
    }

    public List<Long> getReadUserId() {
        return readUserId;
    }

    public void setReadUserId(List<Long> readUserId) {
        this.readUserId = readUserId;
        setUpdateOption();
    }

    public void addReadUserId(long userId){
        if(!this.readUserId.contains(userId)){
            this.readUserId.add(userId);
            setUpdateOption();
        }
    }

    public void addReadUserId(List<Long> userList){
        for (long userId : userList) {
            if(!this.readUserId.contains(userId)){
                this.readUserId.add(userId);
                setUpdateOption();
            }
        }
    }
}
